<?php
class ssi_upload_file {
	var $CI;
	function __construct() {
		$this->CI = & get_instance ();
	}
	public function upload_pic($input_file_name) {
		$base_path = $this->CI->config->item ( 'ssi_file_path' );
		$date_path = "/" . date ( "Y" );
		if (! is_dir ( $base_path . $date_path )) {
			mkdir ( $base_path . $date_path, 0777 );
		}
		$date_path = $date_path . "/" . date ( "m" );
		if (! is_dir ( $base_path . $date_path )) {
			mkdir ( $base_path . $date_path, 0777 );
		}
		$date_path = $date_path . "/" . date ( "d" ) . "/";
		if (! is_dir ( $base_path . $date_path )) {
			mkdir ( $base_path . $date_path, 0777 );
		}
		$config ['upload_path'] = $base_path . $date_path;
		$config ['allowed_types'] = '*';
		$config ['max_size'] = '20000'; // 20M
		$config ['encrypt_name'] = true;
		if (! is_dir ( $config ['upload_path'] )) {
			mkdir ( $config ['upload_path'], 0777 );
		}
		
		$this->CI->load->library ( 'upload', $config );
		if (! $this->CI->upload->do_upload ( $input_file_name )) {
			$data ['result'] = false;
			$data ['message'] = $this->CI->upload->display_errors ( '', '' );
			return $data;
		}
		$upload_info = $this->CI->upload->data ();
		if ($upload_info ['file_ext'] != ".png" && $upload_info ['file_ext'] != ".jpg" && $upload_info ['file_ext'] != ".gif") {
			$data ['result'] = false;
			$data ['message'] = "您上传的必须是一个图像";
			return $data;
		}
		$data ['result'] = true;
		$data ['message'] = $upload_info;
		$data ['upload_file'] = $date_path . $upload_info ['file_name'];
		return $data;
	}
}